<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自定义对象</title>
</head>
<body>

<script>
    //定义一个Peron对象-就是创建一个方法
    function Person() {
    }

    //实例化Person对象
    let p = new Person();
    //动态添加属性和方法
    p.name = 'jerry';
    p.age = 22;
    p.say = function () {
        console.log(this.name + ' say' + ",年龄是：" + this.age);
    }
    //调用方法
    p.say();

    //定义一个自带属性和方法的对象
    function Car(){
        this.name = 'car';
        this.price = 500;
        this.run = function () {
            console.log(this.name + ' is running, price is ' + this.price + '元');
        }
    }
    //实例化Car对象
    let c = new Car();
    c.run();

    //直接实例化对象和方法
    let p2 = {
        name: "jerry_",
        age:111,
        run: function () {
            console.log(this.name + ' is running, age is ' + this.age);
        }
    }
    p2.run();
</script>
</body>
</html>